package controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/ServletMostraImagem")
public class ServletMostraImagem extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ServletMostraImagem() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletOutputStream out = response.getOutputStream();

		File fileimage = new File("D:/Office/WORKSPACE/Faculdades/pooII_2013.1/WebContent/forms/img_ibm.jpg");
        byte [] imagearray;
        imagearray = new byte[(int)fileimage.length ()];
        FileInputStream fis = new FileInputStream (fileimage);

        fis.read (imagearray);
        int i=0;
        while(i<imagearray.length){
            out.write(imagearray[i]);
            ++i;
        }
        
        response.setContentType("image/jpeg");
        response.setContentLength((int)fileimage.length ());

        out.flush();
        out.close();
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}
}